package cn.edu.uestc.smgt.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.uestc.smgt.dao.ManagerMapper;
import cn.edu.uestc.smgt.pojo.Manager;

@Service
public class ManagerService {

	@Autowired
	private ManagerMapper managerMapper;

	/**
	 * 管理员登录系统
	 * 
	 * @return
	 */
	public Manager managerLogin(String username, String password) {
		Manager manager = new Manager();
		manager.setUsername(username);
		manager.setPassword(password);
		return managerMapper.selectByUsernameAndPassword(manager);
	}

	/**
	 * 管理员修改密码:先判断旧密码是否正确，然后修改密码
	 */
	public boolean managerChangePwd(String username, String password, String newPwd) {
		Manager manager = new Manager();
		manager.setUsername(username);
		manager.setPassword(password);
		Manager mgr = managerMapper.selectByUsernameAndPassword(manager);
		if (mgr == null) {
			return false;
		}
		mgr.setPassword(newPwd);
		managerMapper.updateByPrimaryKey(mgr);
		return true;
	}

}
